/**
 * 节点图标
 */
interface NodeIcon{
  icon:string,
  type:string
}

/**
 * 节点图标列表
 */
const nodeIconList: NodeIcon[] = [
  {
    icon: new URL('../assets/git-img.png', import.meta.url).href,
    type: 'git',
  },
  {
    icon: new URL('../assets/maven-img.png', import.meta.url).href,
    type: 'maven',
  },
  {
    icon: new URL('../assets/docker-img.png', import.meta.url).href,
    type: 'docker',
  },
  {
    icon: new URL('../assets/k8s-img.png', import.meta.url).href,
    type: 'k8s',
  },
  {
    icon: new URL('../assets/ssh-img.png', import.meta.url).href,
    type: 'ssh',
  },
  {
    icon: new URL('../assets/sftp-img.png', import.meta.url).href,
    type: 'sftp',
  },
  {
    icon: new URL('../assets/nodejs-img.png', import.meta.url).href,
    type: 'nodejs',
  },
  {
    icon: new URL('../assets/gradle-img.png', import.meta.url).href,
    type: 'gradle',
  },
  {
    icon: new URL('../assets/oss-img.png', import.meta.url).href,
    type: 'oss',
  }
]

/**
 * 获取节点图标
 * @param type 节点类型
 * @returns 返回节点图标
 */
export const getNodeIcon = (type:String):String => {
  const data = nodeIconList.find(i => i.type == type)
  return data ? data.icon : ''
}

/**
 * 节点状态颜色
 */
interface NodeStatusColor{
  status:String,
  color:String
}

/**
 * 状态颜色列表
 */
const statusColorList: NodeStatusColor[] = [
  {
    status: 'init',
    color: '#409EFF'
  },
  {
    status: 'run',
    color: '#E6A23C'
  },
  {
    status: 'success',
    color: '#67C23A'
  },
  {
    status: 'error',
    color: '#F56C6C'
  }
]

/**
 * 获取节点状态颜色
 * @param status 节点状态
 * @returns 
 */
export const getStatusColor = (status:String):String => {
  if(!status){
    return '#409EFF'
  }

  const statusColor = statusColorList.find(i => i.status == status)
  return statusColor ? statusColor.color : '#409EFF'
}